---@type data_componentaction[]
local data = {
    -- 官方的三个组件的修理, finiteuses armor fueled, 给一堆物品时, 尽可能多的消耗物品来修理, 具体数据只需填进 `TUNING.MOD_WEBBER_THE_TRAINER.REPAIR_COMMON`, 此处逻辑不用动
    {
        id = 'ACTION_WEBBER_THE_TRAINER_COMMON_REPAIR',
        str = STRINGS.MOD_WEBBER_THE_TRAINER.ACTIONS.ACTION_COMMON_REPAIR,
        fn = function (act)
            local doer,item,target = act.doer,act.invobject,act.target
            if doer and item and target and doer:IsValid() and item:IsValid() and target:IsValid() then
                local compo = TUNING.MOD_WEBBER_THE_TRAINER.REPAIR_COMMON[target.prefab].type
                local repair_percent = item.prefab and TUNING.MOD_WEBBER_THE_TRAINER.REPAIR_COMMON[target.prefab].repair_percent[item.prefab]
                local cur_percent = target.components[compo] and target.components[compo]:GetPercent()
                if repair_percent and cur_percent then
                    if doer and doer.SoundEmitter then
                        local prefab = item.prefab
                        local sound = (prefab == 'nightmarefuel' or prefab == 'horrorfuel') and 'dontstarve/common/nightmareAddFuel' or 'aqol/new_test/metal'
                        doer.SoundEmitter:PlaySound(sound)
                    end

                    local new_percent = math.min(1,cur_percent + repair_percent)
                    target.components[compo]:SetPercent(new_percent)
                    SUGAR_webber_the_trainer:consumeOneItem(item)

                    while item and item:IsValid() and (target.components[compo]:GetPercent() + repair_percent) <= 1 do
                        local _cur_percent = target.components[compo]:GetPercent()
                        local _new_percent = math.min(1,_cur_percent + repair_percent)
                        target.components[compo]:SetPercent(_new_percent)
                        SUGAR_webber_the_trainer:consumeOneItem(item)
                    end

                    if target:HasTag(target.prefab..'_nodurability') then
                        target:RemoveTag(target.prefab..'_nodurability')
                    end
                    return true
                end
            end
            return false
        end,
        state = 'give',
        actiondata = {
            mount_valid = true,
            priority = 5,
        },
        type = "USEITEM",
        component = 'inventoryitem',
        testfn_type_USEITEM = function (inst, doer, target, actions, right)
            if right and doer:HasTag("player") and target.prefab and TUNING.MOD_WEBBER_THE_TRAINER.REPAIR_COMMON[target.prefab] then
                local canrepair = inst and inst.prefab and TUNING.MOD_WEBBER_THE_TRAINER.REPAIR_COMMON[target.prefab].repair_percent[inst.prefab]
                if canrepair then
                    return true
                end
            end
            return false
        end
    },
    {
        id = 'ACTION_WEBBER_THE_TRAINER_TRADE',
        str = function (act)
            local _tar,_item = act.target,act.invobject
            local _tbl = _item and _tar and trade_data.map[_tar.prefab] and trade_data.map[_tar.prefab][_item.prefab]
            local _str = _tbl and _tbl.str or STRINGS.MOD_WEBBER_THE_TRAINER.ACTIONS.ACTION_WEBBER_THE_TRAINER_TRADE
            return _str
        end,
        fn = function (act)
            local target,item,doer = act.target,act.invobject,act.doer
            if target and item and doer and target:IsValid() and item:IsValid() and doer:IsValid() then
                local fixed = trade_data.map[target.prefab] and trade_data.map[target.prefab][item.prefab] or nil
                local testfn_server = fixed and fixed.testfn_server or nil
                if testfn_server and not testfn_server(item,target,doer) then
                    return false
                end
                if target.components.webber_the_trainer_trader then
                    return target.components.webber_the_trainer_trader:AddOne(item,doer)
                end
            end
            return false
        end,
        state = function (inst, act)
            local _tar,_item = act.target,act.invobject
            local _tbl = _item and _tar and trade_data.map[_tar.prefab] and trade_data.map[_tar.prefab][_item.prefab]
            local sg = _tbl and _tbl.state or 'give'
            return sg
        end,
        actiondata = {
            mount_valid = true,
            priority = 7,
        },
        type = "USEITEM",
        component = 'webber_the_trainer_tradeable',
        testfn_type_USEITEM = function (inst, doer, target, actions, right)
            local fixed = trade_data.map[target.prefab] and trade_data.map[target.prefab][inst.prefab] or nil
            if fixed and target.replica.webber_the_trainer_trader then
                local i,max = fixed.index,fixed.max
                local testfn = fixed.testfn
                local res_testfn = true
                if testfn and not testfn(inst,target,doer) then res_testfn = false end
                return not target.replica.webber_the_trainer_trader:IsMax(i,max) and res_testfn
            end
            return false
        end
    },
    ------------------手杖技能
    -- 手杖的共生加速技能只能韦伯特使用
    {
        id = 'ACTION_WEBBERT_STAFF_ARACHNIDNEXUS_HEALACCEL',
        str = STRINGS.MOD_WEBBER_THE_TRAINER.ACTIONS.ACTION_WEBBERT_STAFF_ARACHNIDNEXUS_HEALACCEL,
        fn = function (act)
            local tar,caster,staff = act.target,act.doer,act.invobject
            if tar and caster and staff and tar:IsValid() and caster:IsValid() and staff:IsValid() then
                if staff.components.staff_arachnidnexus_skill_healaccel then
                    return staff.components.staff_arachnidnexus_skill_healaccel:Cast(caster,tar)
                end
            end
            return false
        end,
        state = "castspell",
        actiondata = {
            distance = 10,
            priority = 7,
            mount_valid = false,
        },
        type = "EQUIPPED",
        component = 'staff_arachnidnexus_skill_healaccel',
        testfn_type_EQUIPPED = function (inst, doer, target, actions, right)
            return inst:HasTag('webbert_rt_panel_active_1') and right and doer.prefab == 'webbert' and doer ~= target and ((target.replica.health and not target.replica.health:IsDead()) or (target:HasTag('player') and not target:HasTag('playerghost')))
        end
    },
    -- 手杖右击再地面的草根树枝根 整齐移植
    {
        id = 'ACTION_WEBBERT_STAFF_TRANSPLANT',
        str = STRINGS.MOD_WEBBER_THE_TRAINER.ACTIONS.ACTION_WEBBERT_STAFF_TRANSPLANT,
        fn = function (act)
            local tar,caster,staff = act.target,act.doer,act.invobject
            if tar and caster and staff and tar:IsValid() and caster:IsValid() and staff:IsValid() then
                if staff.components.webbert_transplant then
                    return staff.components.webbert_transplant:DoAction(caster, tar)
                end
            end
            return false
        end,
        state = 'castspell',
        actiondata = {
            distance = 10,
            priority = 7,
            mount_valid = false,
        },
        type = "EQUIPPED",
        component = 'webbert_transplant',
        testfn_type_EQUIPPED = function (inst, doer, target, actions, right)
            return inst:HasTag('webbert_rt_panel_active_2') and right and (target.prefab == 'dug_sapling' or target.prefab == 'dug_grass')
        end
    },
    -- 待命我的烦人的小妖精们
    {
        id = 'ACTION_WEBBERT_ELF_COMMAND_STANDBY',
        str = STRINGS.MOD_WEBBER_THE_TRAINER.ACTIONS.ACTION_WEBBERT_ELF_COMMAND_STANDBY,
        fn = function (act)
            local staff = act.invobject
            local pt = act:GetActionPoint()
            if staff and staff:IsValid() then
                return staff.components.staff_arachnidnexus_command:DoActionStandBy(pt)
            end
            return false
        end,
        state = 'webbert_whistle',
        actiondata = {
            priority = 7,
            mount_valid = false,
            distance = 15,
        },
        type = "POINT",
        component = 'staff_arachnidnexus_command',
        testfn_type_POINT = function (inst, doer, pos, actions, right)
            return inst:HasTag('webbert_rt_panel_active_3') and right
        end
    },
    -- 召回妖精
    {
        id = 'ACTION_WEBBERT_ELF_COMMAND_CALLBACK',
        str = STRINGS.MOD_WEBBER_THE_TRAINER.ACTIONS.ACTION_WEBBERT_ELF_COMMAND_CALLBACK,
        fn = function (act)
            local staff = act.invobject
            local doer = act.doer
            if staff and staff:IsValid() and doer and doer:IsValid() then
                return staff.components.staff_arachnidnexus_command:DoActionCallBack(doer)
            end
            return false
        end,
        state = 'webbert_whistle',
        actiondata = {
            priority = 7,
            mount_valid = false,
            distance = 15,
        },
        type = 'POINT',
        component = 'staff_arachnidnexus_command',
        testfn_type_POINT = function (inst, doer, pos, actions, right)
            return inst:HasTag('webbert_rt_panel_active_4') and right
        end
    },
    -- 设置elf临时主人 选择elf
    {
        id = 'ACTION_WEBBERT_ELF_COMMAND_SETTEMPMASTER_ELF',
        str = STRINGS.MOD_WEBBER_THE_TRAINER.ACTIONS.ACTION_WEBBERT_ELF_COMMAND_SETTEMPMASTER_ELF,
        fn = function (act)
            local staff = act.invobject
            local tar = act.target
            local doer = act.doer
            if staff and staff:IsValid() and tar and tar:IsValid() and doer and doer:IsValid() then
                return staff.components.staff_arachnidnexus_command:DoActionChooseElf(tar,doer)
            end
            return false
        end,
        state = "give",
        actiondata = {
            priority = 7,
            mount_valid = false,
            distance = 10,
        },
        type = "EQUIPPED",
        component = 'staff_arachnidnexus_command',
        testfn_type_EQUIPPED = function (inst, doer, target, actions, right)
            return inst:HasTag('webbert_rt_panel_active_5') and right and target.prefab == 'webbert_skitter'
        end
    },
    -- 设置elf临时主人 选择player
    {
        id = 'ACTION_WEBBERT_ELF_COMMAND_SETTEMPMASTER_PLAYER',
        str = STRINGS.MOD_WEBBER_THE_TRAINER.ACTIONS.ACTION_WEBBERT_ELF_COMMAND_SETTEMPMASTER_PLAYER,
        fn = function (act)
            local staff = act.invobject
            local p = act.target
            local doer = act.doer
            if staff and staff:IsValid() and p and p:IsValid() and doer and doer:IsValid() then
                return staff.components.staff_arachnidnexus_command:DoActionChoosePlayer(p,doer)
            end
            return false
        end,
        state = "give",
        actiondata = {
            priority = 7,
            mount_valid = false,
            distance = 30,
        },
        type = "EQUIPPED",
        component = 'staff_arachnidnexus_command',
        testfn_type_EQUIPPED = function (inst, doer, target, actions, right)
            return inst:HasTag('webbert_rt_panel_active_5') and right and target ~= doer and target:HasTag('player')
        end
    },
    -- spawn elf
    {
        id = 'ACTION_WEBBERT_ELF_COMMAND_SPAWN',
        str = STRINGS.MOD_WEBBER_THE_TRAINER.ACTIONS.ACTION_WEBBERT_ELF_COMMAND_SPAWN,
        fn = function (act)
            local staff = act.invobject
            local food = act.target
            local doer = act.doer
            if staff and staff:IsValid() and food and food:IsValid() and doer and doer:IsValid() then
                return staff.components.staff_arachnidnexus_command:DoActionSpawnOneElf(food,doer)
            end
            return false
        end,
        state = "castspell",
        actiondata = {
            priority = 7,
            mount_valid = false,
            distance = 30,
        },
        type = "EQUIPPED",
        component = 'staff_arachnidnexus_command',
        testfn_type_EQUIPPED = function (inst, doer, target, actions, right)
            return inst:HasTag('webbert_rt_panel_active_6') and right and target:HasTag('edible') and not target:HasTag('edible_ROUGHAGE') and not target:HasTag('edible_WOOD')
        end
    },
    ---------------------------------------
    -- 木屑面包 吃
    {
        id = 'ACTION_BITE_WEBBERT_BREAD',
        str = STRINGS.MOD_WEBBER_THE_TRAINER.ACTIONS.ACTION_BITE_WEBBERT_BREAD,
        fn = function (act)
            local bread,eater = act.invobject,act.doer
            if bread and eater and bread:IsValid() and eater:IsValid() and bread.components.webbert_bread then
                return bread.components.webbert_bread:Bite(eater)
            end
            return false
        end,
        state = 'eat',
        actiondata = {
            priority = 7,
            mount_valid = true,
        },
        type = 'INVENTORY',
        component = 'webbert_bread',
        testfn_type_INVENTORY = function (inst, doer, actions, right)
            return true
        end
    },
    -- 游戏机 开机
    {
        id = 'ACTION_GAME_POWERON',
        str = STRINGS.MOD_WEBBER_THE_TRAINER.ACTIONS.ACTION_GAME_POWERON,
        fn = function (act)
            local game,doer = act.invobject,act.doer
            if game and game:IsValid() and doer and doer:IsValid() and game.components.webbert_gameconsole then
                return game.components.webbert_gameconsole:PowerOn(doer)
            end
            return false
        end,
        state = 'give',
        actiondata = {
            mount_valid = true,
            priority = 7,
        },
        type = 'INVENTORY',
        component = 'webbert_gameconsole',
        testfn_type_INVENTORY = function (inst, doer, actions, right)
            return true
        end
    },
}

---@type data_componentaction_change[]
local change = {
}

return data,change